/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.service.dxdan;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.acq.entity.dxdan.AcqDxdan;
import com.thinkgem.jeesite.modules.acq.dao.dxdan.AcqDxdanDao;

/**
 * 订销单Service
 * @author lj
 * @version 2018-05-04
 */
@Service
@Transactional(readOnly = true)
public class AcqDxdanService extends CrudService<AcqDxdanDao, AcqDxdan> {

	public AcqDxdan get(String id) {
		return super.get(id);
	}
	
	public List<AcqDxdan> findList(AcqDxdan acqDxdan) {
		return super.findList(acqDxdan);
	}
	
	public Page<AcqDxdan> findPage(Page<AcqDxdan> page, AcqDxdan acqDxdan) {
		return super.findPage(page, acqDxdan);
	}
	
	@Transactional(readOnly = false)
	public void save(AcqDxdan acqDxdan) {
		super.save(acqDxdan);
	}
	
	@Transactional(readOnly = false)
	public void delete(AcqDxdan acqDxdan) {
		super.delete(acqDxdan);
	}
	@Transactional(readOnly = false)
	public Map<String,Object> saveDxdan(AcqDxdan acqDxdan) {
		Map<String,Object> result = new HashMap<String, Object>();
		try{
			super.save(acqDxdan);
			result.put("success", true);
			result.put("message", "订销单信息保存成功");
			return result;
		}catch(Exception e){
			result.put("success", false);
			result.put("message", "网络异常");
			return result;
		}
		
	}
	@Transactional(readOnly = false)
	public Map<String,Object> dxdanList(AcqDxdan acqDxdan) {
		Map<String,Object> result = new HashMap<String, Object>();
		try{
			result.put("list",dao.dxdanList(acqDxdan));
			result.put("success", true);
			result.put("message", "农户订销单列表查询成功");
			return result;
		}catch(Exception e){
			result.put("success", false);
			result.put("message", "网络异常");
			return result;
		}
		
	}
	
	
	@Transactional(readOnly = false)
	public List<Map<String,Object>> dxpie(String areaId) {
		List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
		 List<Map<String,Object>> list = dao.pie(areaId);
		 for(Map<String,Object> map:list){
			 Map<String,Object> temp = new HashMap<String,Object>();
			
			 temp.put("name", ((String)map.get("acq_breed_name")+(String)map.get("acq_plant_name")).replaceAll("null", ""));
			 temp.put("value", (Double)map.get("value"));
			 result.add(temp);
		 }
		return result;
	}
	
	@Transactional(readOnly = false)
	public Map<String,Object> dxline(String areaId) {
		
		Map<String,Object> result = new HashMap<String,Object>();
		List<String> city = new ArrayList<String>();
		List<Double> data = new ArrayList<Double>();
		List<Map<String,Object>> list = dao.line(areaId);
		for(Map<String,Object> map :list){
			city.add((String)map.get("x"));
			data.add((Double)map.get("data"));
		}
		result.put("city",city);
		result.put("data",data);
		return result;
	}
	
}